package com.teradata.cxf.config;

import com.teradata.cxf.server.listmap.ListMapService;
import com.teradata.cxf.server.listmap.ListMapServiceImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

/**
 * 用下面这个地址可以看到发布了哪些服务
 * http://localhost:8002/test
 *
 * https://www.cnblogs.com/hoojo/archive/2011/03/30/1999523.html
 * https://www.cnblogs.com/wangshuai/archive/2009/12/29/1634972.html
 *
 * http://localhost:8002/test/products?wsdl
 * http://localhost:8002/test/user?wsdl
 *
 */
@Configuration
public class CxfConfig {
    //这里有默认值，如果不配置默认是/services/*
    @Bean
    public ServletRegistrationBean dispatcherServlet() {
        return new ServletRegistrationBean(new CXFServlet(), "/test/*");
    }

//    @Autowired
//    private Bus bus;

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

/*
    @Bean
    public CxfService cxfService() {
        return new CxfServiceImpl();
    }
*/

/*
    @Bean
    public CcdcService ccdcService() {
        return new CcdcServiceImpl();
    }
*/

    /*@Bean
    public ContextService contextService() {
        return new ContextServiceImpl();
    }*/

    /*@Bean
    public SimpleService simpleService() {
        return new SimpleServiceImpl();
    }*/

    @Bean
    public ListMapService listMapService() {
        return new ListMapServiceImpl();
    }

    /*@Bean(name = "user")
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), cxfService());
        endpoint.publish("/user");
        return endpoint;
    }*/


    /*@Bean(name = "product")
    public Endpoint endpoint1() {
        EndpointImpl endpoint1 = new EndpointImpl(springBus(), ccdcService());
        endpoint1.publish("/products");
        return endpoint1;
    }*/

    /*@Bean(name = "context")
    public Endpoint endpointContext() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), contextService());
        endpoint.publish("/context");
        return endpoint;
    }*/

    /*@Bean(name = "simple")
    public Endpoint endpointSimple() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), simpleService());
        endpoint.publish("/simple");
        return endpoint;
    }*/

    @Bean(name = "mylistmap")
    public Endpoint endpointListMap() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), listMapService());
        endpoint.publish("/mylistmap");
        return endpoint;
    }

}
